Skip to content

feat(generator): add fallback compatibility imports for google-api-core helpers and update goldens - #17999

Open
hebaalazzeh wants to merge 2 commits into
mainfrom
fallback-api-core
Open

feat(generator): add fallback compatibility imports for google-api-core helpers and update goldens#17999
hebaalazzeh wants to merge 2 commits into
mainfrom
fallback-api-core

Conversation

@hebaalazzeh

@hebaalazzeh hebaalazzeh commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Description

Updates _compat.py.j2 to import helper functions (get_default_mtls_endpoint, get_api_endpoint, get_universe_domain, and transcode_request) from google-api-core, with fallbacks to local implementations for older versions.

Summary of Changes

  • _compat.py.j2: Added try...except ImportError fallback imports for google-api-core helper functions.

Note on setup_request_id

setup_request_id is intentionally kept as a local implementation in _compat.py.j2 rather than imported from google-api-core. The implementation in google-api-core==2.33.0 differs slightly from what the generator expects and will be updated in an upcoming release. Keeping it local avoids dependency mismatches and preserves 100% test coverage.

TODO: update setup_request_id to have try except block once its updated in the upcoming release

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the templates to conditionally import several helper functions (get_default_mtls_endpoint, get_api_endpoint, get_universe_domain, and transcode_request) from google.api_core if available, falling back to local implementations on ImportError. It also updates the client template to explicitly pass default_universe="googleapis.com" to get_universe_domain. The feedback correctly points out that the fallback implementation of get_universe_domain in _compat.py.j2 is missing the default value for default_universe, which breaks compatibility with the original signature and the google.api_core version.

Comment on lines +153 to +156
def get_universe_domain(
*potential_universes: Optional[str],
default_universe: str,
) -> str:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The fallback implementation of get_universe_domain is missing the default value for default_universe (default_universe: str = DEFAULT_UNIVERSE). This breaks compatibility with the original signature and with google.api_core.universe.get_universe_domain, which makes default_universe optional. Please restore the default value to ensure it remains a drop-in replacement.

    def get_universe_domain(
        *potential_universes: Optional[str],
        default_universe: str = DEFAULT_UNIVERSE,
    ) -> str:

@hebaalazzeh hebaalazzeh changed the title WIP feat(generator): add fallback compatibility imports for google-api-core helpers and update goldens Aug 5, 2026
@hebaalazzeh hebaalazzeh self-assigned this Aug 5, 2026
@hebaalazzeh
hebaalazzeh marked this pull request as ready for review August 5, 2026 23:29
@hebaalazzeh
hebaalazzeh requested a review from a team as a code owner August 5, 2026 23:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant